<?php
/**
 * 后台模块管理，用于添加城市、专业等原始数据类
 * edit by gemj
 * 2011－03－20
 */

class EAdmin_Page_CategoryManage extends EAdmin_Page_Abstract
{
    public function validate(ME_Request $input, ME_Response $output)
    {
        $input->doJump = true;
        $adminInfo = Libs_UcUser::getAdminLoginInfo($input,$output);
        $input->adminUser = $output->adminUser = $adminInfo[0];

        $module_list = array();
        $module_arr = Libs_Admin_Module::getModuleList(array());
        if(!empty($module_arr) && is_array($module_arr)){
            foreach ($module_arr as $module){
                $id = $module['id'];
                $name = $module['name'];
                $module_list[$id] = $name;
            }
        }
        $output->module_list = $module_list;

        return true;
    }

    public function doDefault(ME_Request $input, ME_Response $output)
    {
        $page = $input->get('page');
        $m_type = $input->request('m_type');
        $m_type = !empty($m_type) ? $m_type : 0;
        $page = !empty($page) ? $page : 1;
   
        $pagesize = 15;
        $categoryadd = $input->post("categoryadd");
        if(!empty ($categoryadd)){
            $name = $input->post("name");
            $classid = $input->post("classid");
            $subclassid = $input->post("subclassid");
            $module_type = $input->post("module_type");

            Libs_Admin_Category::addCategory(array("module_type"=>$module_type,"classid"=>$classid,"subclassid"=>$subclassid,"name"=>$name));
        }
        if($m_type != 0){
            $type = 3;
        }else{
            $type = 0;
        }
     
        $total = Libs_Admin_Category::getCategoryCount(array("module_type"=>$m_type,"type"=>$type));
       
        $totalpage = ceil($total/$pagesize);
        if($page > $totalpage){
            $page = $totalpage;
        }

        $list = Libs_Admin_Category::getCategoryList(array("module_type"=>$m_type,"type"=>$type,"page"=>$page,"pagesize"=>$pagesize));

        $output->list = $list;
        $output->page = $page;
        $output->m_type = $m_type;
        $output->totalpage = $totalpage;

        $output->setTemplate("CategoryManage");
    }


    #添加新类别
    public function doAddCategory(ME_Request $input, ME_Response $output)
    {
        $catogoryadd = $input->post("catogoryadd");
        $name = $input->post("name");
        $classid = $input->post("classid");
        $subclassid = $input->post("subclassid");
        $module_type = $input->post("module_type");
        $op_tips = "";
        if(!empty ($formhash)){
            Libs_Admin_Module::addModule(array("modulename"=>$name));
            $op_tips = "<font color=\"red\">添加成功！</font>";
        }
        $output->op_tips = $op_tips;

        $output->setTemplate("AddModule");
    }

    /*
     * 删除指定模块
     */
    public function doDelModule(ME_Request $input, ME_Response $output)
    {
        $opid = $input->post("opid");
        if(!empty($opid)){
            Libs_Admin_Module::delModule(array("id"=>$opid));
        }

        $list = Libs_Admin_Module::getModuleList();
        $output->list = $list;

        $output->setTemplate("ModuleManage");
    }
}
